import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import os
import warnings
warnings.filterwarnings('ignore')

root_path = os.path.abspath('../../')
data_path = root_path+"/asset/mergingData100m.csv"
ori_data = pd.read_csv(data_path)

mergingData = ori_data[(ori_data['MergingState']==True) & (ori_data['RouteClass']=='entry') & (ori_data['BreakRuleState']!='No') ]
mergingData['MergingDistance'] = mergingData['MergingDistance'].astype('float')
mergingData['MergingDistanceRatio'] = mergingData['MergingDistanceRatio'].astype('float')
mergingData['MergingDuration'] = mergingData['MergingDuration'].astype('float')
mergingData['MaxLateralSpeed'] = mergingData['MaxLateralSpeed'].astype('float')
mergingData['MaxiLateralAcc'] = mergingData['MaxiLateralAcc'].astype('float')
mergingData['totalvelocity'] = np.sqrt(np.square(mergingData['xVelocity'])+np.square(mergingData['yVelocity']))

mergingData.sort_values(by="vehicleClass", inplace=True)

font1 = {
    'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 14,
}

plt.figure(figsize=(16, 10))

ax1 = plt.subplot(231)
sns.boxplot(x="vehicleClass", y="totalvelocity",data=mergingData,showmeans=True,  whis = 3,showfliers = True)
plt.ylabel("Speed(m/s)",font1)
plt.grid(ls='-',axis="both")
plt.title("Merging Speed",font1)
plt.legend(prop=font1)

ax2 = plt.subplot(232)
sns.boxplot(x="vehicleClass", y="MergingDistance", data=mergingData,showmeans=True, whis = 3,showfliers = True)
plt.ylabel("Distance(m)", font1)
plt.grid(ls='-',axis="both")
plt.title("Merging distance",font1)

ax3 = plt.subplot(233)
sns.boxplot(x="vehicleClass", y="MergingDistanceRatio", data=mergingData, whis = 3, showfliers = True)
plt.ylabel("Ratio", font1)
plt.grid(ls='-',axis="both")
plt.title("Merging distance ratio",font1)

ax4 = plt.subplot(234)
sns.boxplot(x="vehicleClass", y="MergingDuration",data=mergingData,showmeans=True, whis = 3,showfliers = True)
plt.ylabel("Duration(m/s)",font1)
plt.grid(ls='-',axis="both")
plt.title("Merging Duration",font1)
plt.legend(prop=font1)

ax5 = plt.subplot(235)
sns.boxplot(x="vehicleClass", y="MaxLateralSpeed", data=mergingData,showmeans=True, whis = 3,showfliers = True)
plt.ylabel("Speed(m)", font1)
plt.grid(ls='-',axis="both")
plt.title("Merging Lateral Speed",font1)

ax6 = plt.subplot(236)
sns.boxplot(x="vehicleClass", y="MaxiLateralAcc", data=mergingData, whis = 3, showfliers = True)
plt.ylabel("Acceleration", font1)
plt.grid(ls='-',axis="both")
plt.title("Merging Lateral Acceleration",font1)

plt.tight_layout()
plt.show()



